package 面试.OOM;/*
 *@Author: helen
 *@Date:   2021/4/16 16:16
 *@Description:
 */

import java.util.ArrayList;
import java.util.List;

public class GCOverHeadDemo {
    //-Xms20m -Xmx20m -XX:+PrintGCDetails -XX:MaxDirectMemorySize=5m
    public static void main(String[] args) {
        int i = 0;
        List<String > list = new ArrayList<>();
        try{
            while (true) {
                list.add(String.valueOf(++i).intern());
            }
        }catch (Throwable e){
            System.out.println("**************i" + i);
            e.printStackTrace(); //Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
            throw e;
         }
    }
}
